home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2927 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.3 KB

  1. Path: news.cac.psu.edu!usenet
  2. From: "Christopher H. Clark" <chc104@psu.edu>
  3. Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.mac,comp.lang.pascal.ansi-iso,comp.lang.pascal.misc,comp.sys.amiga.programmer,comp.graphics.algorithms,comp.os.ms-windows.programmer.graphics,comp.sys.amiga.graphics
  4. Subject: Re: 3d programming
  5. Date: Tue, 06 Feb 1996 23:56:46 -0500
  6. Organization: Penn State
  7. Message-ID: <3118310E.52F@psu.edu>
  8. References: <4f3od9$2jg@zeus.tcp.co.uk> <jderrick-0502961551360001@slip037.csc.cuhk.hk>
  9. NNTP-Posting-Host: chc104.rh.psu.edu
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. James Derrick wrote:
  16. > In article <4f3od9$2jg@zeus.tcp.co.uk>, agale@agale.tcp.co.uk (Aaron Gale)
  17. > wrote:
  18. > > Does anyone know how to find the intersection of a line and plane
  19. > > in simple x,y and z cartesian coordinates.  I have a model made
  20. > > up of facets, each facet being defined by 4 points.  The working
  21. > > envelope that this model is in, is then scanned from the bottom
  22. > > to the top.  However I can't work out how to calculate the z
  23. > > coordinate along the scan line that may intersect with a facet.
  24. > >
  25. > > The scanning line is always horizontal and is defined with the
  26. > > x and y coordinates remaining the same, with one end of the line
  27. > > minus z and the other end positive z. As an example at what point
  28. > > does the line whose start point is (54,46,-100) and whose end
  29. > > point is (54,46,100) intersect with a plane facet defined by 4
  30. > > points in a anti-clockwise direction point 1 (40,20,-70),
  31. > > point 2 (40,60,-40), point 3 (120,60,-40) and point 4 (120,20,-70).
  32. > You only need 3 points to define a plane.  Using these three points you
  33. > can calculate the equation for the plane by simulaneous equations.
  34. > ie using the first 3 points the equation using a form of z=mx+ny+b would be:
  35. > 1.  -70 = 40m + 20n + b
  36. > 2.  -40 = 40m + 60n + b
  37. > 3.  -40 = 120m + 60n + b
  38. > Solving these gives m=0,n=0.75,b=-85.
  39. > If you had a more complicated line you could solve the intersection also
  40. > by the same method, however as all x & y values are the same, you can just
  41. > substitute the x & y in, which gives you the intersection at (54,46,-50.5)
  42.  
  43. Actually, you only need 2 points to define a plane: a point on the plane and
  44. a normal vector. If your line goes from P0 to P1, and Pt is a point on the 
  45. line, then the following equations hold:
  46.  
  47.     Pt = P0 + t(P1 - P0)    [NOTE: Pt, P1, and P0 are vectors, t is a scalar]
  48.  
  49.     t < 0 or t > 1 --> no intersection
  50.  
  51. If Pe is a point on the plane and N is the inside normal to the plane, then 
  52. the following equations hold:
  53.  
  54.     dot_product( (Pe - Pt), N ) = 0 --> Pt is at the intersection point
  55.                                 > 0 --> Pt is inside the plane
  56.                                 < 0 --> Pt is outside the plane
  57.  
  58.         dot_product( N, (Pe - P0) )
  59.     t = ---------------------------
  60.         dot_product( N, (P1 - P0) )
  61.  
  62. Once you find t, you can find Pt, which is your intersection point. Note that
  63. the equation for t fails if ||N|| = 0 (the 0 vector is usually a bad choice 
  64. for a normal vector :-), if P1 = P0 (no line), or if the line between P1 and P0
  65. is parallel to the plane to which you're clipping (no intersection).
  66.  
  67. Hope this helps
  68. -Chris
  69. -- 
  70.         \\ || //
  71.         \ .  . /
  72. ___.oo0_(__()__)__0oo.___
  73.          
  74.  www.cse.psu.edu/~cclark
  75.